﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace WriteBugs.Controls
{
    /// <summary>
    /// CodeEditor.xaml 的交互逻辑
    /// </summary>
    public partial class CodeEditor : UserControl
    {
        public CodeEditor()
        {
            InitializeComponent();           
        }

                       

        public string CodeEditorText
        {
            get { return (string)GetValue(CodeEditorTextProperty); }
            set { SetValue(CodeEditorTextProperty, value); }
        }

        public static readonly DependencyProperty CodeEditorTextProperty =
        DependencyProperty.Register("CodeEditorText", typeof(string), typeof(CodeEditor), new UIPropertyMetadata(null, CodeEditorTextPropertyChanged));

        private static void CodeEditorTextPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs arg)
        {
            string? Data = (string)arg.NewValue;           

            if (obj is CodeEditor control && Data != null)
            {
                control.TextContainer.Text = Data;
            }
        }

        private void TextContainer_TextChanged(object sender, EventArgs e)
        {
            InputText = this.TextContainer.Text;
        }

        public string InputText
        {
            get { return (string)GetValue(InputTextTextProperty); }
            set { SetValue(InputTextTextProperty, value); }
        }

        public static readonly DependencyProperty InputTextTextProperty =
        DependencyProperty.Register("InputText", typeof(string), typeof(CodeEditor), new UIPropertyMetadata(null, InputTextTextPropertyChanged));

        private static void InputTextTextPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs arg)
        {           
        }

    }
}
